---
category: String
created: '2020-05-16'
title: Get the length of a string in bytes
updated: '2021-10-13'
---

**JavaScript version**

```js bytes.js
const bytes = (str) => new Blob([str]).size;
```

**TypeScript version**

```ts bytes.ts
const bytes = (str: string): number => new Blob([str]).size;
```

**Examples**

```js examples.js
bytes('hello world'); // 11
bytes('🎉'); // 4
```
